#pragma once
#include "DSP.h"
#include "RMSCompute.h"

namespace yzrilyzr_dsp{
	ECLASS(EnvelopDetector, public DSP){
	private:
	u_sample envValue=0;
	u_time_ms deltaTime=0;
	u_time_ms holdTimer=0.0f;
	RMSCompute rmsC;
	public:
	static constexpr int const PEAK=0;
	static constexpr int const RMS=1;
	u_time_ms attack=10;
	u_time_ms hold=500;
	u_time_ms release=100;
	u_time_ms rmsWindow=100;
	int type=PEAK;
	EnvelopDetector();
	EnvelopDetector(u_time_ms attack, u_time_ms hold, u_time_ms release, int type,u_time_ms rmsWindow);
	void init(u_sample_rate sampleRate)override;
	void resetMemory()override;
	std::shared_ptr<DSP> cloneDSP()override;
	void cloneParam(DSP*  obj1)override;
	u_sample procDsp(u_sample v)override;
	u_sample getEnvValue() const;
	yzrilyzr_lang::String toString()const override;
	};
}